![Meet Socket at BlackHat and DEF CON in Las Vegas](https://cdn.sanity.io/images/cgdhsj6q/production/4a3876139ffd3878bb3e7800a14cf4044245dca7-1080x834.jpg?w=400&fit=max&auto=format)
Security News
Meet Socket at BlackHat and DEF CON in Las Vegas
Come meet the Socket team at BlackHat and DEF CON! We're sponsoring some fun networking events and we would love to see you there.
datalib
Advanced tools
Readme
Datalib is a JavaScript data utility library. It provides facilities for data loading, type inference, common statistics, and string templates. While datalib was created to power Vega and related projects, it is also a standalone library useful for data-driven JavaScript applications on both the client (web browser) and server (e.g., node.js).
For documentation, see the datalib API Reference.
Datalib provides a set of utilities for working with data. These include:
Datalib can be used both server-side and client-side. For use in node.js,
simply npm install datalib
or include datalib as a dependency in your package.json file. For use on the client, install datalib via bower install datalib
or include datalib.min.js on your web page. The minified JS file is built using rollup (see below for details).
// Load datalib.
var dl = require('datalib');
// Load and parse a CSV file. Datalib does type inference for you.
// The result is an array of JavaScript objects with named values.
// Parsed dates are stored as UNIX timestamp values.
var data = dl.csv('https://vega.github.io/datalib/data/stocks.csv');
// Show summary statistics for each column of the data table.
console.log(dl.format.summary(data));
// Compute mean and standard deviation by ticker symbol.
var rollup = dl.groupby('symbol')
.summarize({'price': ['mean', 'stdev']})
.execute(data);
console.log(dl.format.table(rollup));
// Compute correlation measures between price and date.
console.log(
dl.cor(data, 'price', 'date'), // Pearson product-moment correlation
dl.cor.rank(data, 'price', 'date'), // Spearman rank correlation
dl.cor.dist(data, 'price', 'date') // Distance correlation
);
// Compute mutual information distance between years and binned price.
var bin_price = dl.$bin(data, 'price'); // returns binned price values
var year_date = dl.$year('date'); // returns year from date field
var counts = dl.groupby(year_date, bin_price).count().execute(data);
console.log(dl.mutual.dist(counts, 'bin_price', 'year_date', 'count'));
To use datalib in the browser, you need to build the datalib.js and datalib.min.js files. We assume that you have npm installed.
npm install
in the datalib folder to install dependencies.npm run build
. This will invoke rollup to bundle the source files into datalib.js, and then uglify-js to create the minified datalib.min.js.If you are using Webpack 1, you need to enable a JSON-loader. To do so, first npm install --save json-loader
, then add the loader to your webpack config:
{
module: {
loaders: [{
test: /\.json$/,
loader: 'json-loader'
}]
}
}
FAQs
JavaScript utilites for loading, summarizing and working with data.
The npm package datalib receives a total of 1,027 weekly downloads. As such, datalib popularity was classified as popular.
We found that datalib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Come meet the Socket team at BlackHat and DEF CON! We're sponsoring some fun networking events and we would love to see you there.
Security News
Learn how Socket's 'Non-Existent Author' alert helps safeguard your dependencies by identifying npm packages published by deleted accounts. This is one of the fastest ways to determine if a package may be abandoned.
Security News
In July, the Python Software Foundation mounted a quick response to address a leaked GitHub token, elected new board members, and added more members to the team supporting PSF and PyPI infrastructure.